package personal.wang.message;

import com.google.protobuf.InvalidProtocolBufferException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import personal.wang.domain.HeartbeatBean;
import personal.wang.inter.MessageDeSe;

/**
 * @className: HeartbeatMessage
 * @Description:
 * @Author: wangyifei
 * @Date: 2025/2/14 17:54
 */
public class HeartbeatMessage extends Message implements MessageDeSe<HeartbeatBean.Heartbeat> {
    private static Logger logger = LoggerFactory.getLogger(HeartbeatMessage.class);

    public HeartbeatMessage(Header header, byte[] content) {
        super(header, content);
    }

    @Override
    public byte[] serialize(HeartbeatBean.Heartbeat input) {
        return input.toByteArray();
    }

    @Override
    public HeartbeatBean.Heartbeat deserialize(byte[] input) {
        HeartbeatBean.Heartbeat heartbeat = null;
        try {
            heartbeat = HeartbeatBean.Heartbeat.parseFrom(input);
        } catch (InvalidProtocolBufferException e) {
            throw new RuntimeException(e);
        }
        return heartbeat;
    }
}
